
    //Var functions 
    var _$table;             //Reference to main <table> (JQuery Object)
    var _$tableBody;         //Reference to body <body> in the table object
    var _$tableRows;         //Array of all <tr> in the table 
    var _$divPagination ;  //Pagination table
    
    var _$totalRecordCount=0; 
    //var pagination
    var _$currentPage = 0;
    var _$numPerPage = 10;



    
    //settings de functions
   var $.fn.stable.default={
          listUrl : '/departamento'
        };

    ///////////////////////////////////////////////////////
    /// CREATE ELEMENTS DOM TABLE
        
    _createTable:function()
     {
            console.log("Create table");
            this._$table=$("<table id='table'></table>")
            .addClass('stdtable');
             
            _createTableHead();
            _createTableBody(); 
     };
        
    _createTableHead:function()
      {
         $tableHead=$('<thead></thead>').
                  appendTo(this._$table);
          
          _addRowTableHead($tableHead);
      }
        
       /*Adds tr element to given thead element*/
    _addRowTableHead:function($tableHead)
      {
           $tr=$('<tr></tr>').
                appendTo($tableHead);
  
            _addRowCellTableHead($tr)
      }
       
       /**Add td element to given tr head element*/
       _addRowCellTableHead:function($tr)
       {
            $td=$('<th>ID</th><th>Nombre</th><th>Descripcion</th><th>Actions</th>')
                   .addClass('head0')
                   .appendTo($tr);
            
            
            //add element table 
            //$('#divTable').append(this._$table);
       }
              
       _createTableBody:function()
       {
           this._$tableBody=$('<tbody></tbody>')
              .appendTo(this._$table);
        
            _addRowTableBody(this._$tableBody);           
       
       }
       
       /* Function add Row table */
        _addRowTableBody:function($body)
       {
           
           $.ajax({
                 type:"POST",
                 url:"departamento/getList",
                 asinc:true,
                 dataType:"json",
                 success:function(data)
                 {
                   if(data.Result='OK')
                    {
                        if(data.TotalRecordCount>0)
                            {
                                _$totalRecordCount=data.TotalRecordCount;
                                _addRecordsToTable(data.Records,$body);
                                _paginationToTable();
                         }
                        else 
                          {
                                _paginationToTable();
                         
                          }
                     }
                   
                 },
                 error:function(data)
                {
                    
                    console.log("error de datoss");
                }
                 
           });
       }
       
       /*********************************************************/
       /*Add a list records to table*/
       _addRecordsToTable:function(records,$body)
       {
           
           //recore la tabla agregando los registros
           $.each(records,function(index,record)
           {
           
               $tr=$('<tr></tr>')
                  .addClass('gradeA odd')
                  .appendTo($body);
                  ///_addRow(_createRowFromRecord(record));
                  var id_data=0;
                  var band=true;
                  for(var i in record)
                   {
                      if(band)
                      {
                         id_data=record[i];
                         band=false;
                      }
                        
                     $td=$("<td>"+record[i]+"</td>")
                         .appendTo($tr);
                      
                   }
                  
                      //edit 
                      $td=$("<td>"+
                             "<a  href='#' id='edit' data-id="+id_data+">"+
                             "<img alt='Edit'></a>"+
                             "</td>"+
                             "<td>"+
                             "<a  href='#' id='delete' data-id="+id_data+">"+
                             "<img alt='Delete'></a>"+
                             "</td>")
                         .appendTo($tr);
           })
           
          
           //add content in table
           $(this).html(this._$table);
           
            //Create la pagination con plugin tablePagination
             console.log("Pagination en script");
             $('tbody tr:odd', $('#table')).hide(); //hiding rows for test
            var options = {
              currPage : 2, 
              ignoreRows : $('tbody tr:odd', $('#table')),
              optionsForRows : [2,3,5],
              rowsPerPage : 5
            }
          
            $('#table').tablePagination(options);


       }